

#include <rtthread.h>
#include <rtdevice.h>
#include "board.h"
#include "drv_gpio.h"

#define uint8   unsigned char
#define uint16  unsigned short
#define uint32  unsigned long


#define KEY_1_PIN       GET_PIN(D, 6)
#define KEY_2_PIN       GET_PIN(B, 5)
#define KEY_3_PIN       GET_PIN(B, 7)
#define KEY_4_PIN       GET_PIN(E, 1)
#define KEY_5_PIN       GET_PIN(E, 0)
#define KEY1_0()      rt_pin_write(KEY_1_PIN, PIN_LOW)
#define KEY2_0()      rt_pin_write(KEY_2_PIN, PIN_LOW)
#define KEY1_1()      rt_pin_write(KEY_1_PIN, PIN_HIGH)
#define KEY2_1()      rt_pin_write(KEY_2_PIN, PIN_HIGH)
#define KEY3_PIN()    rt_pin_read(KEY_3_PIN)
#define KEY4_PIN()    rt_pin_read(KEY_4_PIN)
#define KEY5_PIN()    rt_pin_read(KEY_5_PIN)

#define LCD_RS_PIN     GET_PIN(B, 12)
#define LCD_RW_PIN     GET_PIN(B, 14)
#define LCD_E_PIN      GET_PIN(D, 8)
#define LCD_D0_PIN     GET_PIN(D, 10)
#define LCD_D1_PIN     GET_PIN(D, 12)
#define LCD_D2_PIN     GET_PIN(D, 14)
#define LCD_D3_PIN     GET_PIN(C, 6)
#define LCD_D4_PIN     GET_PIN(C, 8)
#define LCD_D5_PIN     GET_PIN(D, 0)
#define LCD_D6_PIN     GET_PIN(D, 2)
#define LCD_D7_PIN     GET_PIN(D, 4)
#define LCD_RS_0()    rt_pin_write(LCD_RS_PIN, PIN_LOW)
#define LCD_RW_0()    rt_pin_write(LCD_RW_PIN, PIN_LOW)
#define LCD_E_0()     rt_pin_write(LCD_E_PIN,  PIN_LOW)
#define LCD_D0_0()    rt_pin_write(LCD_D0_PIN, PIN_LOW)
#define LCD_D1_0()    rt_pin_write(LCD_D1_PIN, PIN_LOW)
#define LCD_D2_0()    rt_pin_write(LCD_D2_PIN, PIN_LOW)
#define LCD_D3_0()    rt_pin_write(LCD_D3_PIN, PIN_LOW)
#define LCD_D4_0()    rt_pin_write(LCD_D4_PIN, PIN_LOW)
#define LCD_D5_0()    rt_pin_write(LCD_D5_PIN, PIN_LOW)
#define LCD_D6_0()    rt_pin_write(LCD_D6_PIN, PIN_LOW)
#define LCD_D7_0()    rt_pin_write(LCD_D7_PIN, PIN_LOW)
#define LCD_RS_1()    rt_pin_write(LCD_RS_PIN, PIN_HIGH)
#define LCD_RW_1()    rt_pin_write(LCD_RW_PIN, PIN_HIGH)
#define LCD_E_1()     rt_pin_write(LCD_E_PIN,  PIN_HIGH)
#define LCD_D0_1()    rt_pin_write(LCD_D0_PIN, PIN_HIGH)
#define LCD_D1_1()    rt_pin_write(LCD_D1_PIN, PIN_HIGH)
#define LCD_D2_1()    rt_pin_write(LCD_D2_PIN, PIN_HIGH)
#define LCD_D3_1()    rt_pin_write(LCD_D3_PIN, PIN_HIGH)
#define LCD_D4_1()    rt_pin_write(LCD_D4_PIN, PIN_HIGH)
#define LCD_D5_1()    rt_pin_write(LCD_D5_PIN, PIN_HIGH)
#define LCD_D6_1()    rt_pin_write(LCD_D6_PIN, PIN_HIGH)
#define LCD_D7_1()    rt_pin_write(LCD_D7_PIN, PIN_HIGH)

void LCD_init(void) ;
void LCD_PIN_init(void) ;
void KEY_PIN_init(void) ;
void TIMER_init(void) ;
void TIMER_Read(uint8 *Buf) ;

uint8 scan_key(void) ;
void display_lcd_str(uint8 x,uint8 y,uint8 *dbuf,uint8 len) ;

extern uint8 key_data;



